package com.groupbuying.redpacket.controller;

import com.groupbuying.redpacket.domain.ActivityThemeDO;
import com.groupbuying.redpacket.service.ActivityThemeService;
import com.groupbuying.redpacket.utils.apiresult.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/activity")
public class ActivityThemeController {
    @Autowired
    private ActivityThemeService activityThemeService;


    /**
     * 增加活动
     * @param activityThemeDO
     * @return ApiResult
     */
    @PostMapping("/addActivity")
    public ApiResult addActivityTheme(@RequestBody ActivityThemeDO activityThemeDO){
        return activityThemeService.addActivityTheme(activityThemeDO);
    }

    /**
     * 修改活动
     * @param activityThemeDO
     * @return ApiResult
     */
    @PostMapping("/updateActivity")
    public ApiResult updateActivityTheme(@RequestBody ActivityThemeDO activityThemeDO){
        return activityThemeService.updateActivityTheme(activityThemeDO);
    }

    /**
     * 查询活动
     * @return
     */
    @GetMapping("/listActivity")
    public ApiResult listActivity(){
        List<ActivityThemeDO> activityThemeDOS = activityThemeService.listActivity();
        return ApiResult.success(activityThemeDOS);
    }


    /**
     * 根据id查询活动
     * @param id
     * @return
     */
    @GetMapping("/getActivity")
    public ApiResult getActivity(@RequestParam("id") Long id){
        ActivityThemeDO activityThemeDO = activityThemeService.get(id);
        if(activityThemeDO == null){
            return ApiResult.failure("没有该活动");
        }
        return ApiResult.success(activityThemeDO);
    }
}
